/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.tactics;

import robocup.component.SConf;
import robocup.component.ControllerNumbers.PLAY_MODE;
import robocup.component.situations.ScoreSituation;

/**
 * The state that that tries to score. Triggered when with ball and near the 
 * opponents goal.
 *
 * @see ScoreSituation
 */
public class ShootGoalState extends AbstractState {

	/**
	 * Constructor calls superclass constructor.
	 * 
	 * @param parent -
	 *            the StateEvaluation (parent) object
	 */
	public ShootGoalState(StateEvaluation parent) {

		super(parent);
		this.state = STATES.SHOOT_GOAL;
	}

	/**
	 * Precondition true if wiht ball and near the opponents goal.
	 */
	@Override
	public boolean preCondition() {

		if (!checkPlayMode()) {
			return false;
		}

    //only for penalty shoot out
		if (getWorld().getNumber() == 10
				&& PLAY_MODE.META_PENALTY_OWN
						.contains(getWorld().getPlayMode())) {
			if (getWorld().canKick()) {
				return true;
			} else {
				return false;
			}
		}

		if (PLAY_MODE.META_PENALTY_OWN.contains(getWorld().getPlayMode())) {
			return false;
		}

    //if with ball and near the opponents goal
		boolean pre = (checkPlayMode() && checkPlayerHasBall() && this
				.getPlayer().getDistance(SConf.getInstance().GOAL_POS_OTHER) < 35);

		return pre;
	}

	/**
	 * The Probability of scoring.
   * 
   * @see ScoreSituation
	 */
	@Override
	protected double successProbability() {

		return this.getProphet().getScoreBenefit();
	}

	/**
	 * The benefit is max - a goal is our goal!
	 * 
	 * @return 1 - always
	 */
	@Override
	protected double successBenefit() {

		return 1;
	}

  /**
   * the kick calculated in the {@link ScoreSituation}
   */
	@Override
	public void calculateMainAction() {
		mainAction = this.getProphet().getScoreAction();
	}
}
